jQuery(document).ready(function() {
	var totalEntries = jQuery("#totalWordCount").val(); // 单词总数
		jQuery("#pagination").pagination(totalEntries, {
			num_edge_entries : 2,
			num_display_entries : 5,
			callback : pageselectCallback,
			items_per_page : 20
		});
	});

function pageselectCallback(page_index, jq) {
	// 使用ajax获取内容，删除以前的内容，显示新内容
	var wordLibID = jQuery("#wordLibID").val(); // 词库的ID
	var limit = 20; //每页显示单词个数
	

	jQuery.ajax( {
		type : "GET",
		url : "/HealTheWord/wordlib.json" , ///HealTheWord	
		data : "wordLibID=" + wordLibID + "&start=" + page_index * limit + "&limit="
				+ limit + "&n=" + Math.round(100000 * Math.random()),
		dataType : "json",
		error : function() {
			alert('error');
		},
		success : function(data) {
			
			jQuery("#words").empty();
			jQuery("#words").append(
					"<tr>" + "<th>英文单词</th>" + "<th>音标</th>" + "<th>中文含义和例句</th>"
							 + "<th></th>" + "</tr>");
			
			for(var i = 0;i < data.words.length;i++){
				var w = data.words[i];	//单词
				var cn = w.wordCn;		//中文含义串
				var ss = w.sentences;	//例句串
				
				cn = cn.split(";");		//中文含义数组
				ss = ss.split("#");		//例句数组
				
				var cs = "<ul>";		//中文含义和例句的组合html串
				
				for(var j = 0;j < cn.length - 1;j++){
					cs += "<li><div>" + cn[j] + "</div>";
					if(ss[j] != null && ss[j].length > 0 && ss[j].toLowerCase() != "none" && ss[j].toLowerCase() != "null"){
						cs += "<div>" + ss[j] + "</div>";
					}
					cs += "</li>";
				}
				
				cs += "</ul>";
				
				jQuery("#words").append("<tr><td>" + w.wordEn + 
						"</td><td>" + w.phonetics + 
						"</td><td>" + cs + 
						"</td><td><a href='/HealTheWord/administrator/wordlib.htm?method=displayWordForm&wordLibID=" + wordLibID + "&wordID=" + w.wordID + "'>编辑</a>" + 
						"</td><td><a href='/HealTheWord/administrator/wordlib.htm?method=deleteWord&wordLibID=" + wordLibID + "&wordID=" + w.wordID + "'>删除</a>" +
						"</td></tr>");
			}
		}
	});

}
